/*
 * Created by SharpDevelop.
 * User: phtrung
 * Date: 8/11/2008
 * Time: 1:53 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net.Mail;
using System.Collections;
using System.Runtime.InteropServices;
using popLib;

namespace QuickMail
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.TextBox txt_pw;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ListBox lbx_suggest;
		private System.Windows.Forms.CheckBox cb_au;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txt_content;
		private System.Windows.Forms.TextBox txt_to;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox txt_id;
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TabPage tabPage1;
		private System.Windows.Forms.TextBox txt_server;
		private System.Windows.Forms.TabPage tabPage2;
		private System.Windows.Forms.ComboBox cbx_profile;
		private System.Windows.Forms.CheckBox cb_ssl;
		private System.Windows.Forms.TextBox txt_subject;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.TextBox txt_cc;
		private System.Windows.Forms.ListBox lbx_file;
		private System.Windows.Forms.TabPage tabPage3;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.SaveFileDialog saveFileDialog1;
		private System.Windows.Forms.TextBox txt_bcc;
		private System.Windows.Forms.TextBox txt_from;
		private System.Windows.Forms.TextBox txt_port;
		DataSet ds;
		string profileFileName     = (Application.StartupPath + "\\Profile.xml").Replace("\\\\","\\");
		string defaultMailFileName = (Application.StartupPath + "\\DefaultMail.mail").Replace("\\\\","\\");
		
		
		public const int WM_NCLBUTTONDOWN = 0xA1;
		public const int HT_CAPTION = 0x2;
		
		[DllImportAttribute("user32.dll")]
		public static extern int SendMessage(IntPtr hWnd, 
		                 int Msg, int wParam, int lParam);
		[DllImportAttribute("user32.dll")]
		public static extern bool ReleaseCapture();
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.txt_port = new System.Windows.Forms.TextBox();
			this.txt_from = new System.Windows.Forms.TextBox();
			this.txt_bcc = new System.Windows.Forms.TextBox();
			this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
			this.button5 = new System.Windows.Forms.Button();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.tabPage3 = new System.Windows.Forms.TabPage();
			this.lbx_file = new System.Windows.Forms.ListBox();
			this.txt_cc = new System.Windows.Forms.TextBox();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.txt_subject = new System.Windows.Forms.TextBox();
			this.cb_ssl = new System.Windows.Forms.CheckBox();
			this.cbx_profile = new System.Windows.Forms.ComboBox();
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.txt_server = new System.Windows.Forms.TextBox();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.label11 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.label12 = new System.Windows.Forms.Label();
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.txt_id = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.txt_to = new System.Windows.Forms.TextBox();
			this.txt_content = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.cb_au = new System.Windows.Forms.CheckBox();
			this.lbx_suggest = new System.Windows.Forms.ListBox();
			this.label3 = new System.Windows.Forms.Label();
			this.panel1 = new System.Windows.Forms.Panel();
			this.panel2 = new System.Windows.Forms.Panel();
			this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
			this.button4 = new System.Windows.Forms.Button();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.button6 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.label9 = new System.Windows.Forms.Label();
			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
			this.txt_pw = new System.Windows.Forms.TextBox();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.label2 = new System.Windows.Forms.Label();
			this.tabPage2.SuspendLayout();
			this.tabPage1.SuspendLayout();
			this.tabControl1.SuspendLayout();
			this.SuspendLayout();
			// 
			// txt_port
			// 
			this.txt_port.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_port.Location = new System.Drawing.Point(96, 64);
			this.txt_port.Name = "txt_port";
			this.txt_port.Size = new System.Drawing.Size(480, 22);
			this.txt_port.TabIndex = 5;
			this.txt_port.Tag = "1";
			this.txt_port.Text = "";
			// 
			// txt_from
			// 
			this.txt_from.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_from.Location = new System.Drawing.Point(96, 16);
			this.txt_from.Name = "txt_from";
			this.txt_from.Size = new System.Drawing.Size(480, 22);
			this.txt_from.TabIndex = 1;
			this.txt_from.Tag = "1";
			this.txt_from.Text = "";
			this.txt_from.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Txt_fromKeyDown);
			this.txt_from.TextChanged += new System.EventHandler(this.Txt_fromTextChanged);
			this.txt_from.Leave += new System.EventHandler(this.Txt_fromLeave);
			// 
			// txt_bcc
			// 
			this.txt_bcc.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_bcc.Location = new System.Drawing.Point(96, 88);
			this.txt_bcc.Name = "txt_bcc";
			this.txt_bcc.Size = new System.Drawing.Size(480, 22);
			this.txt_bcc.TabIndex = 7;
			this.txt_bcc.Tag = "1";
			this.txt_bcc.Text = "";
			this.txt_bcc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Txt_fromKeyDown);
			this.txt_bcc.TextChanged += new System.EventHandler(this.Txt_fromTextChanged);
			this.txt_bcc.Leave += new System.EventHandler(this.Txt_fromLeave);
			// 
			// saveFileDialog1
			// 
			this.saveFileDialog1.Filter = "Mail file(*.mail)|*.mail|All file(*.*)|*.*";
			// 
			// button5
			// 
			this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button5.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button5.ForeColor = System.Drawing.SystemColors.Control;
			this.button5.Image = ((System.Drawing.Image)(resources.GetObject("button5.Image")));
			this.button5.Location = new System.Drawing.Point(554, 381);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(21, 21);
			this.button5.TabIndex = 14;
			this.button5.Click += new System.EventHandler(this.Button4Click);
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
			this.menuItem1.Text = "Load mail";
			this.menuItem1.Click += new System.EventHandler(this.MenuItem1Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
			this.menuItem2.Text = "Save mail";
			this.menuItem2.Click += new System.EventHandler(this.MenuItem2Click);
			// 
			// tabPage3
			// 
			this.tabPage3.ImageIndex = 2;
			this.tabPage3.Location = new System.Drawing.Point(4, 26);
			this.tabPage3.Name = "tabPage3";
			this.tabPage3.Size = new System.Drawing.Size(592, 500);
			this.tabPage3.TabIndex = 2;
			this.tabPage3.Text = "Close (X)";
			// 
			// lbx_file
			// 
			this.lbx_file.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lbx_file.HorizontalScrollbar = true;
			this.lbx_file.ItemHeight = 14;
			this.lbx_file.Location = new System.Drawing.Point(96, 381);
			this.lbx_file.Name = "lbx_file";
			this.lbx_file.Size = new System.Drawing.Size(456, 88);
			this.lbx_file.TabIndex = 13;
			this.lbx_file.Tag = "2";
			// 
			// txt_cc
			// 
			this.txt_cc.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_cc.Location = new System.Drawing.Point(96, 64);
			this.txt_cc.Name = "txt_cc";
			this.txt_cc.Size = new System.Drawing.Size(480, 22);
			this.txt_cc.TabIndex = 5;
			this.txt_cc.Tag = "1";
			this.txt_cc.Text = "";
			this.txt_cc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Txt_fromKeyDown);
			this.txt_cc.TextChanged += new System.EventHandler(this.Txt_fromTextChanged);
			this.txt_cc.Leave += new System.EventHandler(this.Txt_fromLeave);
			// 
			// openFileDialog1
			// 
			this.openFileDialog1.Multiselect = true;
			// 
			// txt_subject
			// 
			this.txt_subject.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_subject.Location = new System.Drawing.Point(96, 112);
			this.txt_subject.Name = "txt_subject";
			this.txt_subject.Size = new System.Drawing.Size(480, 22);
			this.txt_subject.TabIndex = 9;
			this.txt_subject.Tag = "1";
			this.txt_subject.Text = "";
			// 
			// cb_ssl
			// 
			this.cb_ssl.Location = new System.Drawing.Point(96, 160);
			this.cb_ssl.Name = "cb_ssl";
			this.cb_ssl.Size = new System.Drawing.Size(152, 24);
			this.cb_ssl.TabIndex = 11;
			this.cb_ssl.Tag = "1";
			this.cb_ssl.Text = "SMTP with SS&L";
			// 
			// cbx_profile
			// 
			this.cbx_profile.Location = new System.Drawing.Point(96, 16);
			this.cbx_profile.Name = "cbx_profile";
			this.cbx_profile.Size = new System.Drawing.Size(384, 22);
			this.cbx_profile.TabIndex = 1;
			this.cbx_profile.SelectedIndexChanged += new System.EventHandler(this.ComboBox1SelectedIndexChanged);
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.Add(this.button6);
			this.tabPage2.Controls.Add(this.button3);
			this.tabPage2.Controls.Add(this.cbx_profile);
			this.tabPage2.Controls.Add(this.cb_au);
			this.tabPage2.Controls.Add(this.txt_server);
			this.tabPage2.Controls.Add(this.label7);
			this.tabPage2.Controls.Add(this.panel2);
			this.tabPage2.Controls.Add(this.txt_port);
			this.tabPage2.Controls.Add(this.label8);
			this.tabPage2.Controls.Add(this.txt_id);
			this.tabPage2.Controls.Add(this.label9);
			this.tabPage2.Controls.Add(this.txt_pw);
			this.tabPage2.Controls.Add(this.label10);
			this.tabPage2.Controls.Add(this.cb_ssl);
			this.tabPage2.Controls.Add(this.label11);
			this.tabPage2.ImageIndex = 1;
			this.tabPage2.Location = new System.Drawing.Point(4, 26);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(592, 500);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "Mail settings";
			this.tabPage2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// txt_server
			// 
			this.txt_server.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_server.Location = new System.Drawing.Point(96, 40);
			this.txt_server.Name = "txt_server";
			this.txt_server.Size = new System.Drawing.Size(480, 22);
			this.txt_server.TabIndex = 3;
			this.txt_server.Tag = "1";
			this.txt_server.Text = "";
			// 
			// tabPage1
			// 
			this.tabPage1.Controls.Add(this.lbx_suggest);
			this.tabPage1.Controls.Add(this.lbx_file);
			this.tabPage1.Controls.Add(this.button4);
			this.tabPage1.Controls.Add(this.txt_bcc);
			this.tabPage1.Controls.Add(this.txt_to);
			this.tabPage1.Controls.Add(this.txt_from);
			this.tabPage1.Controls.Add(this.txt_cc);
			this.tabPage1.Controls.Add(this.txt_subject);
			this.tabPage1.Controls.Add(this.txt_content);
			this.tabPage1.Controls.Add(this.label1);
			this.tabPage1.Controls.Add(this.label6);
			this.tabPage1.Controls.Add(this.label5);
			this.tabPage1.Controls.Add(this.label4);
			this.tabPage1.Controls.Add(this.label3);
			this.tabPage1.Controls.Add(this.label2);
			this.tabPage1.Controls.Add(this.panel1);
			this.tabPage1.Controls.Add(this.label12);
			this.tabPage1.Controls.Add(this.button5);
			this.tabPage1.ImageIndex = 0;
			this.tabPage1.Location = new System.Drawing.Point(4, 26);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(592, 500);
			this.tabPage1.TabIndex = 0;
			this.tabPage1.Text = "Send mail";
			this.tabPage1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(16, 16);
			this.label11.Name = "label11";
			this.label11.TabIndex = 0;
			this.label11.Text = "&Profile";
			this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label11.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label10
			// 
			this.label10.Location = new System.Drawing.Point(16, 112);
			this.label10.Name = "label10";
			this.label10.TabIndex = 8;
			this.label10.Text = "P&assword";
			this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label10.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label12
			// 
			this.label12.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label12.Location = new System.Drawing.Point(8, 381);
			this.label12.Name = "label12";
			this.label12.TabIndex = 12;
			this.label12.Text = "F&ile attack";
			this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label12.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// tabControl1
			// 
			this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
						| System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Controls.Add(this.tabPage3);
			this.tabControl1.ImageList = this.imageList1;
			this.tabControl1.ItemSize = new System.Drawing.Size(110, 22);
			this.tabControl1.Location = new System.Drawing.Point(8, 8);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(600, 530);
			this.tabControl1.TabIndex = 3;
			this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.TabControl1SelectedIndexChanged);
			// 
			// txt_id
			// 
			this.txt_id.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_id.BackColor = System.Drawing.Color.Gainsboro;
			this.txt_id.ForeColor = System.Drawing.Color.SteelBlue;
			this.txt_id.Location = new System.Drawing.Point(96, 88);
			this.txt_id.Name = "txt_id";
			this.txt_id.Size = new System.Drawing.Size(480, 22);
			this.txt_id.TabIndex = 7;
			this.txt_id.Tag = "1";
			this.txt_id.Text = "";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(16, 64);
			this.label8.Name = "label8";
			this.label8.TabIndex = 4;
			this.label8.Text = "P&ort";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label8.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// txt_to
			// 
			this.txt_to.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_to.Location = new System.Drawing.Point(96, 40);
			this.txt_to.Name = "txt_to";
			this.txt_to.Size = new System.Drawing.Size(480, 22);
			this.txt_to.TabIndex = 3;
			this.txt_to.Tag = "1";
			this.txt_to.Text = "";
			this.txt_to.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Txt_fromKeyDown);
			this.txt_to.TextChanged += new System.EventHandler(this.Txt_fromTextChanged);
			this.txt_to.Leave += new System.EventHandler(this.Txt_fromLeave);
			// 
			// txt_content
			// 
			this.txt_content.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
						| System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_content.Location = new System.Drawing.Point(96, 136);
			this.txt_content.Multiline = true;
			this.txt_content.Name = "txt_content";
			this.txt_content.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txt_content.Size = new System.Drawing.Size(480, 237);
			this.txt_content.TabIndex = 11;
			this.txt_content.Tag = "1";
			this.txt_content.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(16, 88);
			this.label4.Name = "label4";
			this.label4.TabIndex = 6;
			this.label4.Text = "&Bcc";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(16, 112);
			this.label5.Name = "label5";
			this.label5.TabIndex = 8;
			this.label5.Text = "S&ubject";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label5.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(16, 136);
			this.label6.Name = "label6";
			this.label6.TabIndex = 10;
			this.label6.Text = "C&ontent";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label6.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(16, 40);
			this.label7.Name = "label7";
			this.label7.TabIndex = 2;
			this.label7.Text = "S&erver";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label7.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "&From";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// cb_au
			// 
			this.cb_au.Location = new System.Drawing.Point(96, 136);
			this.cb_au.Name = "cb_au";
			this.cb_au.Size = new System.Drawing.Size(152, 24);
			this.cb_au.TabIndex = 10;
			this.cb_au.Tag = "1";
			this.cb_au.Text = "SMTP au&thenticate";
			// 
			// lbx_suggest
			// 
			this.lbx_suggest.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.lbx_suggest.ItemHeight = 14;
			this.lbx_suggest.Location = new System.Drawing.Point(96, 184);
			this.lbx_suggest.Name = "lbx_suggest";
			this.lbx_suggest.Size = new System.Drawing.Size(480, 88);
			this.lbx_suggest.TabIndex = 16;
			this.lbx_suggest.Visible = false;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 64);
			this.label3.Name = "label3";
			this.label3.TabIndex = 4;
			this.label3.Text = "&Cc";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// panel1
			// 
			this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.panel1.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
			this.panel1.Location = new System.Drawing.Point(576, 486);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(16, 16);
			this.panel1.TabIndex = 2;
			this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseUp);
			this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseDown);
			// 
			// panel2
			// 
			this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.panel2.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
			this.panel2.Location = new System.Drawing.Point(576, 486);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(16, 16);
			this.panel2.TabIndex = 0;
			this.panel2.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseUp);
			this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseDown);
			// 
			// button4
			// 
			this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button4.ForeColor = System.Drawing.SystemColors.Control;
			this.button4.Image = ((System.Drawing.Image)(resources.GetObject("button4.Image")));
			this.button4.Location = new System.Drawing.Point(554, 405);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(21, 21);
			this.button4.TabIndex = 15;
			this.button4.Click += new System.EventHandler(this.Button5Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 3;
			this.menuItem4.Text = "Load sent mail";
			this.menuItem4.Click += new System.EventHandler(this.MenuItem4Click);
			// 
			// button6
			// 
			this.button6.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button6.ForeColor = System.Drawing.SystemColors.Control;
			this.button6.Image = ((System.Drawing.Image)(resources.GetObject("button6.Image")));
			this.button6.Location = new System.Drawing.Point(512, 16);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(21, 21);
			this.button6.TabIndex = 7;
			this.button6.Click += new System.EventHandler(this.Button6Click);
			// 
			// button7
			// 
			this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button7.BackColor = System.Drawing.SystemColors.Control;
			this.button7.ContextMenu = this.contextMenu1;
			this.button7.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button7.Location = new System.Drawing.Point(24, 520);
			this.button7.Name = "button7";
			this.button7.TabIndex = 17;
			this.button7.Text = "&Mail";
			this.button7.Click += new System.EventHandler(this.Button7Click);
			// 
			// button1
			// 
			this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button1.BackColor = System.Drawing.SystemColors.Control;
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button1.Location = new System.Drawing.Point(184, 520);
			this.button1.Name = "button1";
			this.button1.TabIndex = 16;
			this.button1.Text = "&Send";
			this.button1.Click += new System.EventHandler(this.Button1Click);
			// 
			// button2
			// 
			this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.button2.BackColor = System.Drawing.SystemColors.Control;
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button2.Location = new System.Drawing.Point(104, 520);
			this.button2.Name = "button2";
			this.button2.TabIndex = 17;
			this.button2.Text = "&Reset";
			this.button2.Click += new System.EventHandler(this.Button2Click);
			// 
			// button3
			// 
			this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button3.ForeColor = System.Drawing.SystemColors.Control;
			this.button3.Image = ((System.Drawing.Image)(resources.GetObject("button3.Image")));
			this.button3.Location = new System.Drawing.Point(485, 16);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(21, 21);
			this.button3.TabIndex = 6;
			this.button3.Click += new System.EventHandler(this.Button3Click);
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 2;
			this.menuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlD;
			this.menuItem3.Text = "Save as default mail";
			this.menuItem3.Click += new System.EventHandler(this.MenuItem3Click);
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(16, 88);
			this.label9.Name = "label9";
			this.label9.TabIndex = 6;
			this.label9.Text = "&Username";
			this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label9.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// contextMenu1
			// 
			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
						this.menuItem1,
						this.menuItem2,
						this.menuItem3,
						this.menuItem4});
			// 
			// txt_pw
			// 
			this.txt_pw.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
						| System.Windows.Forms.AnchorStyles.Right)));
			this.txt_pw.BackColor = System.Drawing.Color.Gainsboro;
			this.txt_pw.ForeColor = System.Drawing.Color.SteelBlue;
			this.txt_pw.Location = new System.Drawing.Point(96, 112);
			this.txt_pw.Name = "txt_pw";
			this.txt_pw.PasswordChar = '*';
			this.txt_pw.Size = new System.Drawing.Size(480, 22);
			this.txt_pw.TabIndex = 9;
			this.txt_pw.Tag = "1";
			this.txt_pw.Text = "";
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 40);
			this.label2.Name = "label2";
			this.label2.TabIndex = 2;
			this.label2.Text = "&To";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.label2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(7, 15);
			this.BackColor = System.Drawing.Color.Blue;
			this.ClientSize = new System.Drawing.Size(616, 552);
			this.Controls.Add(this.button7);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.tabControl1);
			this.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Quick mail";
			this.TransparencyKey = System.Drawing.Color.Blue;
			this.Load += new System.EventHandler(this.MainFormLoad);
			this.tabPage2.ResumeLayout(false);
			this.tabPage1.ResumeLayout(false);
			this.tabControl1.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion
		
		#region Global Functions
		void initProfile(){
			ds = new DataSet();
			ds.Tables.Add("Profile");
			ds.Tables[0].Columns.Add("Name");
			ds.Tables[0].Columns.Add("Server");
			ds.Tables[0].Columns.Add("Port");
			ds.Tables[0].Columns.Add("Username");
			ds.Tables[0].Columns.Add("Password");
			ds.Tables[0].Columns.Add("Authenticate");
			ds.Tables[0].Columns.Add("SSL");
			
			ds.Tables.Add("MailList");
			ds.Tables[1].Columns.Add("MailName");
			
			if(File.Exists(profileFileName))
				ds.ReadXml(profileFileName);
			else{				
				ds.Tables[0].Rows.Add( new object[]{"Vietcore", "192.168.0.250", "25", "", "","0","0"} );
				ds.Tables[0].Rows.Add( new object[]{"Gmail (port 465 or 587)", "smtp.gmail.com", "465", "require username and password", "","1","1"} );
				ds.Tables[1].Rows.Add( new object[]{"popeveryday@gmail.com"} );
				ds.WriteXml(profileFileName);
			}			
		}
		
		void loadProfile(int profileIndex){
			if( ds != null && ds.Tables.Count>0  && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows.Count > profileIndex){
				txt_server.Text = ds.Tables[0].Rows[profileIndex][1].ToString();
				txt_port.Text 	= ds.Tables[0].Rows[profileIndex][2].ToString();
				txt_id.Text 	= ds.Tables[0].Rows[profileIndex][3].ToString();
				txt_pw.Text 	= ds.Tables[0].Rows[profileIndex][4].ToString();
				cb_au.Checked 	= ds.Tables[0].Rows[profileIndex][5].ToString() == "1" ? true : false;
				cb_ssl.Checked 	= ds.Tables[0].Rows[profileIndex][6].ToString() == "1" ? true : false;
			}				
		}
			
//		string sendMail (string from, string to, string cc, string bcc, string subject, string body, string[] fileAttack, string server, string port, string username, string password, bool authenticate, bool ssl) {
//		    // Mail initialization
//		
//		    MailMessage mailMsg = new MailMessage();
//		    mailMsg.From = from;
//		    mailMsg.To = to;
//		    mailMsg.Cc = cc;
//		    mailMsg.Bcc = bcc;
//		    mailMsg.Subject = subject;
//		    mailMsg.BodyFormat = MailFormat.Text;
//		    mailMsg.Body = body;
//		    mailMsg.Priority = MailPriority.High;
//		    mailMsg.BodyEncoding = System.Text.Encoding.UTF8;		    
//		    foreach( string tmpFile in fileAttack )
//			    if( tmpFile.Trim().Length > 0 && File.Exists(tmpFile) )
//			    	mailMsg.Attachments.Add(new MailAttachment(tmpFile));
//		    // Smtp configuration
//		
//		    SmtpMail.SmtpServer = server;
//		    // - smtp.gmail.com use smtp authentication
//		
//		    if(authenticate) mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//		    
//		    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
//		    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
//		    // - smtp.gmail.com use port 465 or 587
//		
//		    mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port);
//		    // - smtp.gmail.com use STARTTLS (some call this SSL)
//		
//		    if(ssl) mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
//		    // try to send Mail
//		
//		    try
//		    {
//		        SmtpMail.Send(mailMsg);
//		        return "";
//		    }
//		    catch (Exception ex) 
//		    {
//		        return ex.Message;
//		    }
//		}
		
		bool validation(){
			string controlName = ",txt_from,txt_to,txt_server,txt_port,";
			Control[] allControl = getChildControlList( this.Controls );
			string error = "";
			foreach( Control con in allControl )
				if( controlName.IndexOf(","+con.Name+",") >= 0 && con.Text.Trim().Length == 0 )
					error+= con.Name + " is required!\r\n";
			
			if( error != "" ){
				MessageBox.Show( "There some error:\r\n" + error );
				return false;
			}			
			
			return true;
		}
		
		Control[] getChildControlList( System.Windows.Forms.Control.ControlCollection controls ){
			ArrayList list = new ArrayList();
			
			list.AddRange( controls );
			
			for(int i=0;i<controls.Count;i++){
				if(controls[i].ToString().IndexOf("TabPage:")==0)
					list.AddRange( getChildControlList( ((TabPage)controls[i]).Controls ) );
				if(controls[i].ToString().IndexOf(".TabControl")>=0)
					list.AddRange( getChildControlList( ((TabControl)controls[i]).Controls ) );
				if(controls[i].ToString().IndexOf(".Panel")>=0)
					list.AddRange( getChildControlList( ((Panel)controls[i]).Controls ) );
				if(controls[i].ToString().IndexOf(".GroupBox")>=0)
					list.AddRange( getChildControlList( ((GroupBox)controls[i]).Controls ) );
			}
			Control[] result = new Control[list.Count];
			list.CopyTo( result );
			return result;			
		}
				
		DataSet ds_currentMail;
		void initDefaultMail(){						
			ds_currentMail = new DataSet();
			ds_currentMail.Tables.Add("Mail");
			ds_currentMail.Tables[0].Columns.Add("From");
			ds_currentMail.Tables[0].Columns.Add("To");
			ds_currentMail.Tables[0].Columns.Add("Cc");
			ds_currentMail.Tables[0].Columns.Add("Bcc");
			ds_currentMail.Tables[0].Columns.Add("Subject");
			ds_currentMail.Tables[0].Columns.Add("Content");
			ds_currentMail.Tables[0].Columns.Add("File");
			
			if(File.Exists(defaultMailFileName)){				
				loadMail(defaultMailFileName);
			}
		}
		
		public void loadMail(string fileName){
			ds_currentMail.Tables[0].Rows.Clear();
			ds_currentMail.ReadXml(fileName);
			
			txt_from.Text 		= ds_currentMail.Tables[0].Rows[0][0].ToString();
			txt_to.Text 		= ds_currentMail.Tables[0].Rows[0][1].ToString();
			txt_cc.Text 		= ds_currentMail.Tables[0].Rows[0][2].ToString();
			txt_bcc.Text 		= ds_currentMail.Tables[0].Rows[0][3].ToString();
			txt_subject.Text 	= ds_currentMail.Tables[0].Rows[0][4].ToString();
			txt_content.Text 	= ds_currentMail.Tables[0].Rows[0][5].ToString();
			lbx_file.Items.Clear();
			lbx_file.Items.AddRange( ds_currentMail.Tables[0].Rows[0][6].ToString().Replace("\r\n", (char)(128)+"").Split((char)(128)) );
			lbx_file.Items.RemoveAt(lbx_file.FindStringExact(""));
		}		
		
		void saveMail(string fileSave){
							
				ds_currentMail.Tables[0].Rows.Clear();
				string fileList = "";
				for( int i=0; i< lbx_file.Items.Count; i++ )
					fileList+= lbx_file.Items[i].ToString()+"\r\n";
				ds_currentMail.Tables[0].Rows.Add( new object[]{
				                      txt_from.Text,
				                      txt_to.Text,
				                      txt_cc.Text,
				                      txt_bcc.Text,
				                      txt_subject.Text,
				                      txt_content.Text,
				                      fileList
				                      } );
				ds_currentMail.WriteXml(fileSave);
		}
		
		void updateMailList(string mail){
			if(mail.Trim().Length == 0) return;
									
			if(mail.IndexOf(";") >= 0 || mail.IndexOf(",") >= 0){
				string[] mailList = mail.Split(';');
				if(mail.IndexOf(",") >= 0) mailList = mail.Split(',');				
				foreach(string onemail in mailList)
					updateMailList(onemail);
				return;
			}			
			
			foreach( DataRow row in ds.Tables[1].Rows ){
				if(row[0].ToString() == mail) return;
			}
			ds.Tables[1].Rows.Add( new object[]{mail});
			ds.WriteXml(profileFileName);
			loadSuggestMail();
		}
		
		void loadSuggestMail(){			
			lbx_suggest.Items.Clear();			
			foreach( DataRow row in ds.Tables[1].Rows )
				lbx_suggest.Items.Add(row[0]);
			
		}
		#endregion
		
		#region Form Functions
		private void Form1_MouseDown(object sender,System.Windows.Forms.MouseEventArgs e)
		{     
		    if (e.Button == MouseButtons.Left)
		    {
		        ReleaseCapture();
		        SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
		    }
		}
		
		int x = -1; int y=-1;
		void Panel1MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			x = e.X;
			y = e.Y;
		}
		
		void Panel1MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			this.Width -= x - e.X;
			this.Height-= y - e.Y;
		}
		
		void ComboBox1SelectedIndexChanged(object sender, System.EventArgs e)
		{
			loadProfile( cbx_profile.SelectedIndex );
		}
				
		void MainFormLoad(object sender, System.EventArgs e)
		{
			initProfile();
			initDefaultMail();
			loadSuggestMail();
			cbx_profile.DataSource    = ds;
			cbx_profile.DisplayMember = "Profile.Name";
			cbx_profile.ValueMember   = "Profile.Name";
			txt_from.Select();
		}
				
		void Button1Click(object sender, System.EventArgs e)
		{
			if(validation()){
				string[] fileAtt = new string[lbx_file.Items.Count];
				lbx_file.Items.CopyTo( fileAtt, 0 );
				
				string rs = NetLib.sendMail( txt_from.Text, 
				                     txt_to.Text, 
				                     txt_cc.Text, 
				                     txt_bcc.Text, 
				                     txt_subject.Text, 
				                     txt_content.Text, 
				                     fileAtt, 
				                     txt_server.Text, 
				                     NumberLib.getInt(txt_port.Text),
				                     txt_id.Text, 
				                     txt_pw.Text,
				                     cb_ssl.Checked
				                     );
				
				
				
				if(rs != "") MessageBox.Show(rs);
				else{
					MessageBox.Show("Send mail done.");
					
					string dir_sent = Application.StartupPath + "\\Sent";
					if( !Directory.Exists(dir_sent) ) Directory.CreateDirectory( dir_sent );
					string file_sentMail = dir_sent + "\\Sent - " + DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mail";
					saveMail( file_sentMail );
				}
				updateMailList( txt_from.Text );
				updateMailList( txt_to.Text );
				updateMailList( txt_cc.Text );
				updateMailList( txt_bcc.Text );
			}
		}
				
		void Button4Click(object sender, System.EventArgs e)
		{
			openFileDialog1.Filter = "";
			if(openFileDialog1.ShowDialog().ToString() == "OK"){
				if(lbx_file.FindStringExact( openFileDialog1.FileName ) == -1)
					foreach( string addedFile in openFileDialog1.FileNames)
						lbx_file.Items.Add(addedFile);
				
				lbx_file.SelectedIndex = lbx_file.FindStringExact( openFileDialog1.FileName );
				toolTip1.SetToolTip( lbx_file, lbx_file.SelectedItem.ToString() );
			}
		}
		
		void Button5Click(object sender, System.EventArgs e)
		{
			if(lbx_file.SelectedIndex >= 0){
				lbx_file.Items.RemoveAt( lbx_file.SelectedIndex );
				if(lbx_file.Items.Count > 0) lbx_file.SelectedIndex = 0;
			}
		}
		
		void TabControl1SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(tabControl1.SelectedIndex == 2){
				while(this.Opacity > 0) this.Opacity -= 0.01;
				this.Close();
			}
		}
		
		//add new profile
		void Button3Click(object sender, System.EventArgs e)
		{
			ds.Tables[0].Rows.Add( new object[]{ cbx_profile.Text, txt_server.Text, txt_port.Text, txt_id.Text, txt_pw.Text } );
			ds.WriteXml(profileFileName);
		}
		
		void Button6Click(object sender, System.EventArgs e)
		{
			if( cbx_profile.SelectedIndex >= 0 && MessageBox.Show("Remove profile: "+cbx_profile.Text+"?", "Confirm", MessageBoxButtons.OKCancel).ToString() == "OK"){
				ds.Tables[0].Rows.RemoveAt(cbx_profile.SelectedIndex);
				ds.WriteXml(profileFileName);
			}
		}
		
		void Button2Click(object sender, System.EventArgs e)
		{
			Control[] cons = getChildControlList( this.Controls );
			foreach(Control con in cons){
				if(con.Tag != null){
					if(con.Tag.ToString() == "1") con.Text = "";
					if(con.Tag.ToString() == "2") ((ListBox)con).Items.Clear();
				}
			}
		}
		
		void Button7Click(object sender, System.EventArgs e)
		{
			contextMenu1.Show( button7, new Point(0,0) );
		}
						
		void MenuItem1Click(object sender, System.EventArgs e)
		{
			openFileDialog1.Filter = saveFileDialog1.Filter;
			if(openFileDialog1.ShowDialog().ToString() == "OK"){				
				loadMail(openFileDialog1.FileName);
			}
		}
				
		void MenuItem2Click(object sender, System.EventArgs e)
		{
			if(saveFileDialog1.ShowDialog().ToString() == "OK"){				
				saveMail(saveFileDialog1.FileName);
			}
		}
		
		void MenuItem3Click(object sender, System.EventArgs e)
		{
			saveMail( (Application.StartupPath + "\\DefaultMail.mail").Replace("\\\\","\\") );
		}
							
		void Txt_fromKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{			
			
			if(	e.KeyValue == 27 )
				lbx_suggest.Hide();
			else if(	e.KeyValue == 13 && lbx_suggest.SelectedIndex >= 0 ){
				((TextBox)sender).Text = lbx_suggest.Text;
				lbx_suggest.Hide();
			}else if(	e.KeyValue == 38 && lbx_suggest.SelectedIndex > 0 )
				lbx_suggest.SelectedIndex--;
			else if( e.KeyValue == 40 && lbx_suggest.SelectedIndex < lbx_suggest.Items.Count-1 )
				lbx_suggest.SelectedIndex++;
		}
		
		void Txt_fromTextChanged(object sender, System.EventArgs e)
		{
			int index = lbx_suggest.FindString( ((TextBox)sender).Text );
			if(index >= 0 && ((TextBox)sender).Text.Trim().Length > 0 ){
				lbx_suggest.Show();
				lbx_suggest.Location = new Point( lbx_suggest.Location.X, ((TextBox)sender).Location.Y + ((TextBox)sender).Height );
				lbx_suggest.SelectedIndex = index;
			}else if(((TextBox)sender).Text.Trim().Length == 0)
				lbx_suggest.Hide();
		}
		
		void Txt_fromLeave(object sender, System.EventArgs e)
		{
			lbx_suggest.Hide();
		}
		#endregion
		void MenuItem4Click(object sender, System.EventArgs e)
		{
			Mail mail = new Mail(this);
			mail.ShowDialog();
		}
		
	}
}
